<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>表单提交工具 | xiaohe66</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <link rel="stylesheet" href="../plugin/layui/css/layui.css" media="all">
</head>
<body>
<blockquote class="layui-elem-quote layui-text" style="margin-top: 20px;">
    postman不支持文件下载。该工具就是为此而生的
</blockquote>
<div class="layui-col-lg5">
    <form class="layui-form" action="" lay-filter="source">
        <div class="layui-form-item">
            <label class="layui-form-label">地址</label>
            <div class="layui-input-block">
                <input type="text" name="url" lay-verify="required" autocomplete="off" class="layui-input"
                       value="http://localhost:8080/">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-block">
                <input type="text" name="method" lay-verify="required" autocomplete="off" placeholder="请输入类型"
                       class="layui-input" value="POST">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">参数</label>
            <div class="layui-input-block">
                <textarea name="params" class="layui-textarea" placeholder="参数1:值&#13;参数2:值"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="confirm">提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<div style="display: none">
    <form id="form" method="post" target="_blank">
    </form>
</div>
<script src="../plugin/layui/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        let form = layui.form,
            $ = layui.$;

        form.on('submit(confirm)', function (data) {

            let field = data.field;

            let f = $("#form");
            f.attr("action", field.url);
            f.attr("method", field.method);

            let arr = field.params.split("\n");

            f.html("");
            $.each(arr, function (i, item) {
                let param = item.split(":");
                f.append("<input name='" + param[0] + "' value='" + param[1] + "'>");
            });
            f.submit();

            return false;
        });

    });
</script>
</body>
</html>